<!DOCTYPE HTML>
<html>

<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./css/index.css">
<title>Erasing Information</title>
</head>

<body id="fondo">
<div id="cuerpo">
<fieldset style="width: 1000px; color: #FFF;";>
<?php
        include 'header.php';

$selected=$_POST['selected'];
$link = mysqli_connect('localhost', 'root', '');

if (mysqli_connect_errno()) {
        echo 'You cannot connect to mysql';
        exit;
}

$sql = "USE web_db";
$resultado = mysqli_query($link,$sql);

switch ($selected) {
    case "country":
        $sql=Sel_Country();
        break;
    case "mecha":
    	$sql=Sel_Mecha();
    	break;
    case "mission":
    	$sql=Sel_Mission();
    	break;
    case "news":
    	$sql=Sel_News();
    	break;
    case "part":
    	$sql=Sel_Part();
    case "staff":
    	$sql=Sel_Staff();
    	break;
    case "country_mission":
    	$sql=Sel_Country_Miss();
    	break;
    case "mech_mission":
    	$sql=Sel_Mech_Miss();
    	break;
    case "mech_part":
    	$sql=Sel_Mech_Part();
    	break;
    case "rank":
        $sql=Sel_Rank();
        break;
}

$data = mysqli_query ($link,$sql)or die($mysqli->error);

if($data){
	echo "You erased from $selected succesfully";
}

function Sel_Country() {
	$code=$_POST['erase_id'];

	$query = "DELETE FROM country WHERE code='$code'";
	return $query;
}

function Sel_Mecha() {
	$mec=$_POST['erase_id'];

	$query = "DELETE FROM mecha WHERE mec_id='$mec'";
	return $query;
}

function Sel_Mission() {
	$miss_nr=$_POST['erase_id'];

	$query = "DELETE FROM mission WHERE miss_nr='$miss_nr'";
	return $query;
}

function Sel_News() {
	$n_nr=$_POST['erase_id'];

	$query = "DELETE FROM news WHERE n_nr='$n_nr'";
	return $query;
}

function Sel_Part() {
	$sn=$_POST['erase_id'];

	$query = "DELETE FROM part WHERE sn='$sn'";
	return $query;
}

function Sel_Staff() {
	$id=$_POST['erase_id'];

	$query = "DELETE FROM staff WHERE id='$id'";
	return $query;	
}

function Sel_Mech_Miss() {
	$mec=$_POST['erase_id'];

	$query = "DELETE FROM mech_mission WHERE mec_id='$mec'";
	return $query;
}

function Sel_Country_Miss() {
	$code=$_POST['erase_id'];

	$query = "DELETE FROM country_mission WHERE code='$code'";
}

function Sel_Mech_Part() {
	$mec=$_POST['erase_id'];

	$query = "DELETE FROM mech_part WHERE mec_id='$mec'";
	return $query;
}

function Sel_Rank() {
    $rank=$_POST['erase_id'];

    $query = "DELETE FROM rank WHERE rank_nr='$rank'";
    return $query;
}

    header("location:table_data.php");
?>

<p>Would you like to come back?</p>
<a HREF="admin.php"><input type="button" value="Administration"></a>
<form name="table_select" method='POST' action="table_data.php">
	<input type="hidden" name="tabla" value=<?php echo "'$selected'"; ?> />
	<input type="submit" value="Table Data">
</form>
<a HREF="index.php"><input type="button" value="Index"></a>
<?php
    include 'footer.php';
?>
</fieldset>
</div>
</body>